# from flask import Flask, jsonify, request
# # import threading
# # import sys
# # from productionline.LongMenPage import PInput3D
#
#
# app = Flask(__name__)
# # result = [False, "", "", "", "", "", "", "", "", ""]
#
# # 定义一个路由，用于获取最新的x值      这段代码中 get_LongMenResult 路由函数被定义为处理客户端请求的函数  就是说，客户端提出请求这段代码才会执行
# @app.route('/get_longMen')
# def get_LongMenResult(result):
#
#     response = {
#         'is_work': result[0],
#         'work': result[1],
#         'item1_name': result[2],
#         'item1_status': result[3],
#         'item2_name': result[4],
#         'item2_status': result[5],
#         'item3_name': result[6],
#         'item3_status': result[7],
#         'item4_name': result[8],
#         'item4_status': result[9]
#     }
#     return jsonify(response)
#
# # def update_shuru():
# #     global result
# #     while True:
# #         shuru = input("请输入操作指令")
# #         result = PInput3D(shuru)
# #
# # # 启动一个新线程来更新x值
# # thread = threading.Thread(target=update_shuru)
# # thread.start()
#
# if __name__ == '__main__':
#     # 运行Flask应用
#     app.run(host='0.0.0.0', port=5000)

from flask import Flask, jsonify, request
import threading
import sys


from LongMenPage import PInput3D,getHouseStatus

app = Flask(__name__)
result = [False, "", "", "", "", "", "", "", "", ""]
user_input = ""

# 定义一个路由，用于获取最新的x值      这段代码中 get_LongMenResult 路由函数被定义为处理客户端请求的函数  就是说，客户端提出请求这段代码才会执行
@app.route('/get_longMen')
def get_LongMenResult():
    global result
    global user_input
    result = getHouseStatus(user_input)
    print("helllo my name")
    response = {
        # 'is_work': result[0],
        # 'work': result[1],
        # 'item1_name': result[2],
        # 'item1_status': result[3],
        # 'item2_name': result[4],
        # 'item2_status': result[5],
        # 'item3_name': result[6],
        # 'item3_status': result[7],
        # 'item4_name': result[8],
        # 'item4_status': result[9]
        'status': result[1],
    }
    return jsonify(response)

# def set_LongMenResult(res):
#     global result
#     result = res

def update_shuru():
    global user_input
    while True:

        user_input = input("请输入操作指令")
        PInput3D(user_input)


# 启动一个新线程来更新x值
thread = threading.Thread(target=update_shuru)
thread.start()

if __name__ == '__main__':
    # 运行Flask应用
    app.run(host='0.0.0.0', port=5001)
